package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.jiayang.hhotel.R;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2017/5/24 0024.
 * 换房对话框适配器(现住详情菜单项)
 */

public class ChangeRoomDialogAdapter extends BaseAdapter{

    private Context t;
    private List<String> mList;
    private HashMap<Integer,String> selectRoom;
    public ChangeRoomDialogAdapter(Context context, List<String> list){
        this.t=context;
        this.mList=list;
        this.selectRoom=new HashMap<>();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    ViewHolder holder;
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        String room=mList.get(position);
        if(convertView==null){
            convertView= LayoutInflater.from(t).inflate(R.layout.divide_gridview_item,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder= (ViewHolder) convertView.getTag();
        holder.item.setText(room);
        holder.item.setTag(position);
        holder.item.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if((Integer)buttonView.getTag()==position&&isChecked){
                    selectRoom.put(position,String.valueOf(buttonView.getText()));
                }
            }
        });
        return convertView;
    }

    public HashMap<Integer,String> getSelectRoom(){
        return selectRoom;
    }

    public class ViewHolder{
        CheckBox item;

        public ViewHolder(View view){
            item= (CheckBox) view.findViewById(R.id.cb);
        }
    }

}
